package com.xsomnus.java_basic.proxy;

import com.xsomnus.java_basic.proxy.test.IUserService;
import com.xsomnus.java_basic.proxy.test.User;
import com.xsomnus.java_basic.proxy.test.impl.UserServiceImpl;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/7/19 0019 11:48
 * - 才需学也,学需静也/非淡泊无以明志，非宁静无以致远
 * <desc>
 * 静态代理就是基于代理模式实现的实现
 * </desc>
 */

public class StaicProxy implements IUserService {

    private IUserService target = new UserServiceImpl();

    @Override
    public User save(User user) {
        System.out.println("开启事务");
        try {
            final User save = target.save(user);
            System.out.println("提交事务");
            return save;
        } catch (Exception e) {
            System.out.println("回滚事务");
        }
        return null;
    }

    public void save22() {
        System.out.println("0000");
        //new StaicProxy().save(null);
        //target.save(null);
        System.out.println("1111");
    }

    @Override
    public User getByUserId(String userId) {
        return target.getByUserId(userId);
    }
}
